import 'package:flutter/material.dart';
import '../../base/MyScaffold.dart';
import '../../widgets/MyLocalImage.dart';
import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart';

import '../../res.dart';
import '../../utils/color/ColorUtils.dart';
import '../../widgets/TextView.dart';

class Permissions extends StatefulWidget {
  const Permissions({Key? key}) : super(key: key);

  @override
  State<Permissions> createState() => _PermissionsState();
}

class _PermissionsState extends State<Permissions> {
  @override
  Widget build(BuildContext context) {
    return MyScaffold(
      navBarHide: true,
      body: Container(
        alignment: Alignment.center,
        padding: const EdgeInsets.symmetric(horizontal: 32),
        child: Column(
          children: [
            const SizedBox(
              height: 100,
            ),
            const MyLocalImage(
              Res.sys_img_loa,
              width: 100,
              height: 100,
            ),
            TextView(
              "Required permissions",
              alignment: Alignment.centerLeft,
              margin: const EdgeInsets.only(top: 40, bottom: 20),
              style: TextStyle(
                  color: rgba(48, 49, 51, 1),
                  fontSize: 20,
                  fontWeight: FontWeight.bold),
            ),
            Text.rich(TextSpan(children: [
              const TextSpan(text: "To read and edit documents, allow "),
              TextSpan(
                  text: "PDF Editor ",
                  style: TextStyle(color: rgba(255, 78, 77, 1))),
              const TextSpan(text: "access to all your files ")
            ], style: TextStyle(color: ColorUtils.text, fontSize: 16))),
            const Spacer(),
            TextView(
              "Allow",
              height: 48,
              style: const TextStyle(
                  color: Colors.white,
                  fontSize: 16,
                  fontWeight: FontWeight.bold),
              alignment: Alignment.center,
              radius: BorderRadius.circular(6),
              backcolor: rgba(255, 78, 77, 1),
              onclick: () async {
                await Permission.storage.request().then((status) {
                  // if (status.isGranted) {
                  //   Get.back();
                  // }
                  // if (!status.isDenied) {
                  //   openAppSettings();
                  // } else {}

                  if (status.isDenied) {

                  } else if (status.isPermanentlyDenied) {
                    //永久拒绝了权限 提示用户
                    openAppSettings();
                  } else {
                    //通过权限申请
                    Get.back();
                  }
                });
              },
            ),
            TextView(
              "later",
              height: 48,
              alignment: Alignment.center,
              margin: const EdgeInsets.symmetric(vertical: 5),
              style: TextStyle(
                  color: rgba(
                    150,
                    151,
                    153,
                    1,
                  ),
                  fontWeight: FontWeight.bold),
            ),
          ],
        ),
      ),
    );
  }
}
